//
//  MyMoneyViewController.m
//  XTXOneToOne
//
//  Created by Canny on 2018/11/2.
//  Copyright © 2018年 WK. All rights reserved.
//

#import "MyMoneyViewController.h"
#import "MyMoneySlideView.h"
#import "BBMoneyModel.h"
#import "BBRechargeViewController.h"
#import "HZViewController.h"

@interface MyMoneyViewController ()

@property (nonatomic,strong)MyMoneySlideView * segmentedView;

@end

@implementation MyMoneyViewController

- (void)viewDidLoad {
    
    [super viewDidLoad];
    [self setProperty];
    [self createUI];


    
}

-(void)viewWillAppear:(BOOL)animated{
    
    [super viewWillAppear:animated];
    [UIApplication sharedApplication].statusBarHidden = NO;
    
    self.navigationController.navigationBar.translucent = YES;
    self.navigationController.navigationBarHidden=YES;
    
}

-(void)setProperty{
    
    self.view.backgroundColor=RGB(255, 255, 255);
    
    [UIApplication sharedApplication].statusBarHidden = NO;
    
    self.navigationController.navigationBar.translucent = YES;
    self.navigationController.navigationBarHidden=YES;
    
    self.baseVcTitle = @"我的资产";
    
}

-(void)createUI{
    NSArray *array = [NSArray arrayWithObjects:@"币币资产",@"杠杆资产",nil];
    _segmentedView = [MyMoneySlideView segmentControlViewWithFrame:CGRectMake(0, 0, G_SCREENWIDTH, G_SCREENHEIGHT-kStatusBarAndNavigationBarHeight)];
    
    WS(weakSelf);
    _segmentedView.normalColor = RGB(102,102,102);
    _segmentedView.selectedColor = MC_THEME_COLOR;
    _segmentedView.SlideSelectedColor=MC_THEME_COLOR;
    _segmentedView.backgroundColor=[UIColor whiteColor];
    _segmentedView.titleArray = array;
    _segmentedView.selectedTitleArray = array;
    [self.bgView addSubview:_segmentedView];
    _segmentedView.BBBlock = ^(BBlistMoneyModel * _Nonnull model, NSString * _Nonnull Type) {
        if ([Type isEqualToString:@"充值"]) {
            
            BBRechargeViewController * VC = [[BBRechargeViewController alloc]init];
            VC.dataSource = model;
            [weakSelf.navigationController pushViewController:VC animated:YES];
            
        }else{
            
            [weakSelf assets_prerecharge:model or:nil andType:@"BB"];

        }
    };
    
    _segmentedView.GGBlock = ^(GGlistMoneyModel * _Nonnull model, NSString * _Nonnull Type) {
        
        [weakSelf assets_prerecharge:nil or:model andType:@"GG"];
    };
    
}

#pragma mark- 检测是否允许资金划转
-(void)assets_prerecharge:(BBlistMoneyModel * )model1 or:(GGlistMoneyModel * )model2 andType:(NSString *)Type{
    
    NSString * URL = [NSString stringWithFormat:@"%@assets/prerecharge",DEFAULTSEVERBASEURL];
    
    NSDictionary * Dic =@{
                          };
    [HUD showProgress:@"" inView:self.bgView];
    WS(weakSelf);
    
    [MOLoadHttpsData GetHttpDataWithUrlStr:URL Dic:Dic SuccessBlock:^(id  _Nonnull responseObject) {
        [HUD dismissInView:weakSelf.bgView];
        
        NSDictionary * dic = responseObject;
        
        NSString * code = [NSString stringWithFormat:@"%@",dic[@"code"]];
        NSString * msg = [NSString stringWithFormat:@"%@",dic[@"msg"]];
        
        if ([code isEqualToString:@"0"]) {
            HZViewController * VC = [[HZViewController alloc]init];
            if ([Type isEqualToString:@"GG"]) {
                VC.GGmodel = model2;
                VC.Type=@"杠杆资产";
            }else{
                VC.BBmodel = model1;
                VC.Type=@"币币资产";
            }
            [weakSelf.navigationController pushViewController:VC animated:YES];
        }else{
            
            [HUD showErrorMessage:msg];
            
        }
        
        
        
    } FailureBlock:^(id  _Nonnull error) {
        [HUD dismissInView:weakSelf.bgView];
    }];
    
    
    
    
}


@end
